package vip.zhenzicheng.design_patterns.interpreter;

/**
 * 减法表达式类
 *
 * @author zhenzicheng
 * @date 2022-05-27 15:01
 */
public class Minus extends AbstractExpression {

  //-号左边的表达式
  private final AbstractExpression left;
  //-号右边的表达式
  private final AbstractExpression right;

  public Minus(AbstractExpression left, AbstractExpression right) {
    this.left = left;
    this.right = right;
  }

  @Override
  public int interpret(Context context) {
    //将左边表达式的结果和右边表达式的结果进行相减
    return left.interpret(context) - right.interpret(context);
  }

  @Override
  public String toString() {
    return "(" + left.toString() + " - " + right.toString() + ")";
  }
}
